<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鼠标经过div发post请求，将响应体的内容呈现再div</title>
    <style>
        div{
            width: 200px;
            height: 200px;
            border: 1px solid #ccc;
        }
    </style>
</head>
<body>
    <div id="result"></div>
<script>
    var div=document.querySelector('#result');
    div.addEventListener('mouseover',function (){
        const xhr=new XMLHttpRequest();
        xhr.open('post','http://127.0.0.1:5050/server');
        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xhr.send('a=100&b=90');
        xhr.addEventListener('readystatechange',function(){
            if(xhr.readyState===4){
                if(xhr.status>=200&&xhr.status<300){
                    div.innerHTML=xhr.response;
                }
            }
        })
    })
</script>
</body>
</html>